<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引入css -->
    <link rel="stylesheet" href="../assets/lib/NProgress/NProgress.css">
    <!-- 引入友好的提示框css -->
    <link rel="stylesheet" href="../assets/lib/toastr/toastr.min.css">
</head>
<body>
    <!-- 引入拦截器的js -->
    <script src="../assets/lib/axios.js"></script>
    <!-- 引入NProgress的js -->
    <script src='../assets/lib/NProgress/NProgress.js'></script>
    <!-- 引入友好的提示框jquery -->
    <script src="../assets/lib/jquery-3.6.0.min.js"></script>
    <!-- 引入友好的提示框js -->
    <script src="../assets/lib/toastr/toastr.min.js"></script>

    <script>
          // 放入拦截器的代码 在官网cv
      // 添加请求拦截器
      axios.interceptors.request.use(
        function (config) {
            
          
          //显示进度条
        NProgress.start()
          return config;
        },
        function (error) {
          
          return Promise.reject(error);
        }
      );

      // 添加响应拦截器
      axios.interceptors.response.use(
        function (response) {
            //关闭进度条
            NProgress.done()
            //业务状态码出错  response === .then 的result           
            console.log(response);
            //code = 0 正确 不等于0 是错误的
            if(response.data.code !== 0){
                toastr.error(response.data.message)
            }
          return response;
        },
        function (error) {
            //关闭进度条
            NProgress.done()
            //状态码出错的提示
            toastr.error(error.response.data.message)
          return Promise.reject(error);
        }
      );

      axios({
          url: "http://www.itcbc.com:8000/api/login",
          method:'post',
          data:{
            username:'111',
            password:'1111111111',
          },
        }).then((result) => {
          console.log(result);
        });
    </script>
</body>
</html>